#include "singnalandslot.h"
#include "ui_singnalandslot.h"


//引入一个表格类
#include<QGridLayout>
#include<QDebug>

#define PI 3.14

SingnalAndSlot::SingnalAndSlot(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::SingnalAndSlot)
{
    ui->setupUi(this);

    this->setWindowTitle("calc");

    //创建标签
    lab1 = new QLabel(this);
    lab1->setText("请输入圆的半径：");

    //创建显示结果的标签
    lab2 = new QLabel(this);

    //创建输入框
    lin1 = new(QLineEdit);

    //创建一个按钮
    btn = new QPushButton(this);
    btn->setText("计算圆的体积");

    QGridLayout* qgl = new QGridLayout(this);
    qgl->addWidget(lab1,0,0);
    qgl->addWidget(lin1,0,1);
    qgl->addWidget(btn,1,0);
    qgl->addWidget(lab2,1,1);

    connect(btn,&QPushButton::clicked,this,&SingnalAndSlot::Calcation);
}

SingnalAndSlot::~SingnalAndSlot()
{
    delete ui;
}
void SingnalAndSlot::Calcation(){
    bool ok;
    QString str = lin1->text();
    int R = str.toInt(&ok);
    lab2->setText(QString::number(4/3*R*R*R*PI));
}
